/*****************************************************************
*
*	Netcare Agent Project
*		Copyright(C) 2010, Wicresoft EKA. All Rights Reserved.
*
*	Authors:
*		Miles Chen (milesch@wicresoft.com)
*		TingRong Shi (trshi@wicresoft.com)
*
*	Part of the product code depends on gSOAP under GPL license
*		Copyright(C) 2000-2010, Robert van Engelen, Genivia Inc. All Rights Reserved.
*
*****************************************************************/
#include <cstdio>

#include "DateTime.h"

NETCARE_AGENT;

USING_STD;

#define DATE_LENGTH 11
#define DATE_TIME_LENGTH 20

#ifdef WIN32
#define __sprintf _snprintf
#define __swprintf swprintf
#else
#define __sprintf snprintf
#define __swprintf swprintf
#endif

CDateTime::CDateTime(const time_t& t) : _data(t)
{
}

CDateTime::~CDateTime(void)
{
}

CDateTime* CDateTime::Now()
{
	return new CDateTime(time(NULL));
}

string CDateTime::ToDateString() const
{
	char buffer[DATE_LENGTH];
	tm* p = localtime(&_data);

	__sprintf(buffer, DATE_LENGTH, "%04d-%02d-%02d", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday);

	return string(buffer);
}
string CDateTime::ToString() const
{
	char buffer[DATE_TIME_LENGTH];
	tm* p = localtime(&_data);

	__sprintf(buffer, DATE_TIME_LENGTH, "%04d-%02d-%02d %02d:%02d:%02d", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);

	return string(buffer);
}
wstring CDateTime::ToDateStringW() const
{
	wchar_t buffer[DATE_LENGTH];
	tm* p = localtime(&_data);

	__swprintf(buffer, DATE_LENGTH, L"%04d-%02d-%02d", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday);

	return wstring(buffer);
}
wstring CDateTime::ToStringW() const
{
	wchar_t buffer[DATE_TIME_LENGTH];
	tm* p = localtime(&_data);

	__swprintf(buffer, DATE_TIME_LENGTH, L"%04d-%02d-%02d %02d:%02d:%02d", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);

	return wstring(buffer);
}



ENDNS ENDNS